
<h1><span class="yiyi-st" id="yiyi-12">numpy.asarray_chkfinite</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray_chkfinite.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray_chkfinite.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.asarray_chkfinite"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">asarray_chkfinite</code><span class="sig-paren">(</span><em>a</em>, <em>dtype=None</em>, <em>order=None</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/lib/function_base.py#L970-L1034"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">将输入转换为数组，检查NaN或Infs。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-15">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-16"><strong>a</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-17">输入数据，以任何形式可以转换为数组。</span><span class="yiyi-st" id="yiyi-18">这包括列表，元组列表，元组，元组元组，列表和ndarrays的元组。</span><span class="yiyi-st" id="yiyi-19">成功不需要NaN或Infs。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-20"><strong>dtype</strong>：数据类型，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">默认情况下，从输入数据推断数据类型。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-22"><strong>order</strong>：{&apos;C&apos;，&apos;F&apos;}，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-23">是否使用行主（C风格）或列主（Fortran风格）内存表示。</span><span class="yiyi-st" id="yiyi-24">默认为&apos;C&apos;。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-25">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-26"><strong>out</strong>：ndarray</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-27">数组解释<em class="xref py py-obj">a</em>。</span><span class="yiyi-st" id="yiyi-28">如果输入已经是ndarray，则不执行复制。</span><span class="yiyi-st" id="yiyi-29">如果<em class="xref py py-obj">a</em>是ndarray的子​​类，则返回基类ndarray。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-30">上升：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-31"><strong>ValueError</strong></span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-32">如果<em class="xref py py-obj">a</em>包含NaN（不是数字）或Inf（无穷大），则引发ValueError。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-33">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-34"><a class="reference internal" href="numpy.asarray.html#numpy.asarray" title="numpy.asarray"><code class="xref py py-obj docutils literal"><span class="pre">asarray</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-35">创建和数组。</span></dd>
<dt><span class="yiyi-st" id="yiyi-36"><a class="reference internal" href="numpy.asanyarray.html#numpy.asanyarray" title="numpy.asanyarray"><code class="xref py py-obj docutils literal"><span class="pre">asanyarray</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-37">类似的函数通过子类。</span></dd>
<dt><span class="yiyi-st" id="yiyi-38"><a class="reference internal" href="numpy.ascontiguousarray.html#numpy.ascontiguousarray" title="numpy.ascontiguousarray"><code class="xref py py-obj docutils literal"><span class="pre">ascontiguousarray</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-39">将输入转换为连续数组。</span></dd>
<dt><span class="yiyi-st" id="yiyi-40"><a class="reference internal" href="numpy.asfarray.html#numpy.asfarray" title="numpy.asfarray"><code class="xref py py-obj docutils literal"><span class="pre">asfarray</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-41">将输入转换为浮点数。</span></dd>
<dt><span class="yiyi-st" id="yiyi-42"><a class="reference internal" href="numpy.asfortranarray.html#numpy.asfortranarray" title="numpy.asfortranarray"><code class="xref py py-obj docutils literal"><span class="pre">asfortranarray</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-43">将输入转换为具有列主存储器顺序的ndarray。</span></dd>
<dt><span class="yiyi-st" id="yiyi-44"><a class="reference internal" href="numpy.fromiter.html#numpy.fromiter" title="numpy.fromiter"><code class="xref py py-obj docutils literal"><span class="pre">fromiter</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-45">从迭代器创建数组。</span></dd>
<dt><span class="yiyi-st" id="yiyi-46"><a class="reference internal" href="numpy.fromfunction.html#numpy.fromfunction" title="numpy.fromfunction"><code class="xref py py-obj docutils literal"><span class="pre">fromfunction</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-47">通过在网格位置上执行函数来构造数组。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-48">例子</span></p>
<p><span class="yiyi-st" id="yiyi-49">将列表转换为数组。</span><span class="yiyi-st" id="yiyi-50">如果所有元素都是有限的<code class="docutils literal"><span class="pre">asarray_chkfinite</span></code>与<code class="docutils literal"><span class="pre">asarray</span></code>相同。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">asarray_chkfinite</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
<span class="go">array([1., 2.])</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-51">如果array_like包含Nans或Infs，则引发ValueError。</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
<span class="gp">... </span>    <span class="n">np</span><span class="o">.</span><span class="n">asarray_chkfinite</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="gp">... </span><span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s1">&apos;ValueError&apos;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">ValueError</span>
</pre></div>
</div>
</dd></dl>
